import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

Blockly.Blocks.yield_function = {
  init: function () {
    this.appendValueInput('yieldStatement').setCheck(null).appendField('yield')
    this.setInputsInline(false)
    this.setOutput(true)
    this.setColour(230)
    this.setTooltip('yield关键字(可以不写value)')
    this.setHelpUrl('')
  }
}

Blockly.Python.yield_function = function (block) {
  const yieldStatement = Blockly.Python.valueToCode(
    block,
    'yieldStatement',
    // eslint-disable-next-line no-undef
    Blockly.Python.ORDER_NONE
  )
  let code = ''
  code = 'yield ' + yieldStatement + '\n'
  return [code, Blockly.Python.ORDER_NONE]
}

export default Blockly
